<?php
/**
 * 内链关键词
 * 所有分类
 * 产品、新闻、单页 填写的内链关键词
 * 自主添加
 * 		词
 * 		链接
 */
class WordAction extends AdminbaseAction {


	public $db = 'inner_keyword';

	function _initialize() {

		parent::_initialize();

	}

	function index(){
		
		$post_list = M('posts')->field('ID as id , inner_keyword as name, view as click')->where("inner_keyword <> ''")->select();
		foreach ($post_list as $key => $value) {
			$post_list[$key]['type'] = 'post';
		}

		$term_list = M('terms')->field('term_id as id , name , count as click')->select();
		foreach ($term_list as $key => $value) {
			$term_list[$key]['type'] = 'term';
		}

		// p($term_list);

		$list = M($this->db)->select();

		$list = array_merge($list,array_merge($term_list,$post_list));
		// p($list);
		$this->keyword_list = $list;
		$this->display();
	}
	
	
	function add(){
         $this->display();
	}
	
	function add_post(){

		if (IS_POST) {
			$data = I('post.');

			// pe($data);
			$result = M($this->db)->add($data);

			// $result=$this->posts_obj->add($_POST['post']);
			if ($result) {
				$this->success("新增成功！");
			} else {
				$this->error("新增失败！");
			}
		}
	}
	
	function edit(){

		$id = I('get.id');

		$info = M($this->db)->where('id = '.$id)->find();

		$this->assign($info);

		$this->display();
	}
	
	public function edit_post(){
	
		if (IS_POST) {
			$data = I('post.');
			
			// pe($data);
			$result = M($this->db)->where('id = '.$data['id'])->save($data);

			if ($result !== false) {
				//
				$this->success("保存成功！");
				//$this->success(json_encode($_POST['meta']));
			} else {
				$this->error("保存失败！");
			}
		}
	}
	

	
	/**
	 * 单页删除
	 * @return [type] [description]
	 */
	function delete(){
		
		if(IS_GET){
			// echo I('get.id');
			// 
			$result = M($this->db)->where('id = '.I('get.id'))->delete();

			if($result){
				$this->success('删除成功');
			}else{
				$this->error('删除失败');
			}
		}

	}
	

	
	
	
}